package demo;

import java.util.Objects;

/**
 * //todo
 *
 * @author dingwen
 * 2021.06.09 14:33
 */
public class ObjectEq {
    public static void main(String[] args) {
        String str1 = new String("ding");
        String str2 = "ding";
        String str3 = null;

        // 避免空指针异常
        System.out.println(Objects.equals(str1, str2));

        // 地址比较 两个String 一定使用equals 进行比较
        System.out.println(str1 == str2);

        System.out.println(Objects.equals(str3, str2));

        //str3 NullPointerException
        System.out.println(str3.equals(str2));
    }
}
